package expriment3_bag;
public class Seven {
    public static void main(String[] args) {
        System.out.println("=====以下为本人所写代码：=====");
        int Table[][] = {
                { 23, 45, 65, 34, 21, 67, 78 },
                { 46, 14, 18, 46, 98, 63, 88 },
                { 98, 81, 64, 90, 21, 14, 23 },
                { 54, 43, 55, 76, 22, 43, 33 }
        };
        int []rowi=new int[Table.length];
        for(int i=0;i<rowi.length;i++){
            rowi[i]=0;
        }
        for (int i = 0; i < Table.length; i++) {
            for (int j = 0; j < Table[i].length; j++) {
                rowi[i]=rowi[i]+Table[i][j];
            }
        }
        int maxi=0;
        for(int i=1;i<rowi.length;i++) {
            if (rowi[i] > rowi[maxi]) {
                maxi= i;
            }
        }
        int sumi=0;
        for(int i=0;i<Table[maxi].length;i++) {
            sumi=sumi+Table[maxi][i];
        }
        System.out.println("第"+(maxi+1)+"行元素之和最大,和为"+sumi);
        System.out.println("====以下为实验书上的代码：====");
        int myTable[][] = { { 23, 45, 65, 34, 21, 67, 78 },
                { 46, 14, 18, 46, 98, 63, 88 }, { 98, 81, 64, 90, 21, 14, 23 },
                { 54, 43, 55, 76, 22, 43, 33 } };
        int sum, max, maxRow = 0;
        max = 0; // 假设所有的值都为正数
        for (int row = 0; row < 4; row++) {
            sum = 0;
            for (int col = 0; col < 7; col++)
                sum += myTable[row][col];
            if (sum> max) {
                max = sum;
                maxRow = row;
            }
        }
        System.out.println("Row " + maxRow + " has the highest sum of " + max);
    }
}
